package com.ruoyi.web.controller.customer;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.employee.domain.CrmEmployee;
import com.ruoyi.employee.service.ICrmEmployeeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户员工Controller
 * 
 * @author hct
 * @date 2022-02-11
 */
@RestController
@RequestMapping("/employee/employee")
public class CrmEmployeeController extends BaseController
{
    @Autowired
    private ICrmEmployeeService crmEmployeeService;

    /**
     * 查询客户员工列表
     */
    @PreAuthorize("@ss.hasPermi('employee:employee:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmEmployee crmEmployee)
    {
        startPage();
        List<CrmEmployee> list = crmEmployeeService.selectCrmEmployeeList(crmEmployee);
        return getDataTable(list);
    }

    /**
     * 导出客户员工列表
     */
    @PreAuthorize("@ss.hasPermi('employee:employee:export')")
    @Log(title = "客户员工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmEmployee crmEmployee)
    {
        List<CrmEmployee> list = crmEmployeeService.selectCrmEmployeeList(crmEmployee);
        ExcelUtil<CrmEmployee> util = new ExcelUtil<CrmEmployee>(CrmEmployee.class);
        util.exportExcel(response, list, "客户员工数据");
    }

    /**
     * 获取客户员工详细信息
     */
    @PreAuthorize("@ss.hasPermi('employee:employee:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmEmployeeService.selectCrmEmployeeById(id));
    }

    /**
     * 新增客户员工
     */
    @PreAuthorize("@ss.hasPermi('employee:employee:add')")
    @Log(title = "客户员工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmEmployee crmEmployee)
    {
        return toAjax(crmEmployeeService.insertCrmEmployee(crmEmployee));
    }

    /**
     * 修改客户员工
     */
    @PreAuthorize("@ss.hasPermi('employee:employee:edit')")
    @Log(title = "客户员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmEmployee crmEmployee)
    {
        return toAjax(crmEmployeeService.updateCrmEmployee(crmEmployee));
    }

    /**
     * 删除客户员工
     */
    @PreAuthorize("@ss.hasPermi('employee:employee:remove')")
    @Log(title = "客户员工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmEmployeeService.deleteCrmEmployeeByIds(ids));
    }
}
